package NewTmas.Listeners;

import NewTmas.FramesandPanels.JobGraphPanel;
import NewTmas.Graphs.JGraphGenerated;
import NewTmas.PrintJGraphMenuItem;

import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import java.util.HashSet;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: abhatnag
 * Date: 8/9/11
 * Time: 3:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class PrintGraphMenuListener implements MenuListener {

    HashSet<String> jobSet=new HashSet<String>();
    JMenu printGraphs;
    JMenuItem  jobGraphItem=null;
    List<JobGraphPanel> graphPanels;
    String selectedLib;

    public PrintGraphMenuListener(HashSet<String> jobSet, JMenu printGraphs, List<JobGraphPanel> graphPanels, String selectedLib) {
        this.jobSet=jobSet;
        this.printGraphs=printGraphs;
        this.graphPanels=graphPanels;
        this.selectedLib=selectedLib;
    }

    public void menuSelected(MenuEvent e) {
        printGraphs.removeAll();


        if(selectedLib.equalsIgnoreCase("GraphViz"))
        {
            for (String str:jobSet)
            {
                jobGraphItem = new JMenuItem(str+".pdf");
                jobGraphItem.addActionListener(new PrintGraphListener(str,graphPanels));
                printGraphs.add(jobGraphItem);
            }
        }
        else{

            for(JobGraphPanel j:graphPanels){
                printGraphs.add(new PrintJGraphMenuItem(   ((JGraphGenerated)j.getGraphObj()).graphComponent  ,    j.job  ));

            }

        }
    }

    public void menuDeselected(MenuEvent e) {

    }

    public void menuCanceled(MenuEvent e) {

    }
}
